home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 076-100 / disk_085 / rawio / testraw.c < prev   
C/C++ Source or Header  |  1992-05-06  |  2KB  |  65 lines

  1. /*
  2.  *    testraw.c
  3.  *
  4.  *   This program shows how to use the functions raw() and cooked() to
  5.  * control the way characters are read from a Level 2 file pointer.
  6.  * These are only useful if the file pointer points at an instance of
  7.  * the console.device, which means one of 'stdin', 'stdout', or 'stderr'
  8.  * or a console opened with fp = fopen("CON:x/y/wid/len/Title","w+");
  9.  * like this example does. 
  10.  *
  11.  * Written : 16-Jun-87 By Chuck McManis, do with it what you will.
  12.  *
  13.  */
  14.  
  15. #include <stdio.h>
  16. #ifndef u_char
  17. #define    u_char    unsigned char
  18. #endif
  19.  
  20. void main()
  21.  
  22. {
  23.   FILE    *win;
  24.   char    c;
  25.   long    i;
  26.  
  27.   printf("This program shows how to use raw mode file pointers.\n");
  28.   printf("First we open the window...\n");
  29.   win = fopen("CON:10/10/400/100/Test Console","w+");
  30. /* If opening a file, use setnbf() to set it to unbuffered mode, this is
  31.  * very importatant. Not required for stdin since Lattice defaults it to
  32.  * unbuffered. 
  33.  */
  34.   setnbf(win);
  35.   fprintf(win,"Using the default mode, type some characters ... \n");  
  36.   fprintf(win,"Type a 'Q' to go to next phase ... \n");  
  37.   i = 0;
  38.   while ((c = fgetc(win)) != 'Q') {
  39.     i = (i + 1) % 25;
  40.     if (i == 0) printf("\n");
  41.     printf(" %02x",(u_char) c);
  42.   }
  43.   printf("\n************\n");
  44.   fprintf(win,"Now switching to 'raw' mode ...\n");
  45.   fprintf(win,"Type a 'Q' to go to next phase ... \n");  
  46.   if (raw(win) != 0) perror("raw");
  47.   i = 0;
  48.   while ((c = fgetc(win)) != 'Q') {
  49.     i = (i + 1) % 25;
  50.     if (i == 0) printf("\n");
  51.     printf(" %02x",(u_char) c);
  52.   }
  53.   printf("\n************\n");
  54.   fprintf(win,"Now back to 'cooked' mode ... \n");
  55.   fprintf(win,"Type a 'Q' to quit ... \n");  
  56.   if (cooked(win) != 0) perror("cooked");
  57.   i = 0;
  58.   while ((c = fgetc(win)) != 'Q') {
  59.     i = (i + 1) % 25;
  60.     if (i == 0) printf("\n");
  61.     printf(" %02x",(u_char) c);
  62.   }
  63.   fclose (win);
  64. }
  65.